﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Willow.Authorization;
using Willow.MVC.Search;
using Willow.MVC.Result;
namespace Willow.WebApplication.Areas.Auth.Controllers
{
    public class OnlineUserController : Controller
    {
        #region 页面

        /// <summary>
        /// 在线用户列表
        /// </summary>
        /// <returns></returns>
        public ViewResult List()
        {
            return View();
        }

        #endregion

        #region 操作

        /// <summary>
        /// 强制退出
        /// </summary>
        /// <param name="sessionIDs">The session i ds.</param>
        /// <returns></returns>
        public JsonResult ForceQuit(string[] sessionIDs)
        {
            return this.StandardJson(() =>
            {
                foreach (string item in sessionIDs)
                {
                    OnlineContext.Instance.RemoveUser(item);
                }
            });
        }

        /// <summary>
        /// 获取分页后信息
        /// </summary>
        /// <param name="page">The page.</param>
        /// <param name="rows">The rows.</param>
        /// <param name="sort">The sort.</param>
        /// <param name="order">The order.</param>
        /// <param name="fullName">The full name.</param>
        /// <returns></returns>
        public JsonResult GetPagedList(int page, int rows, string sort, string order, string fullName)
        {
            var allUsers = OnlineContext.Instance.GetAllUser();
            if (!string.IsNullOrEmpty(fullName))
            {
                allUsers = allUsers.Where(p => p.FullName.Contains(fullName));
            }
            var lstData = allUsers.Skip((page - 1) * rows).Take(rows);
            var total = allUsers.Count();
            return Json(new { rows = lstData, total });
        }

        #endregion
    }
}